package org.mokusakura.service.impl;

import org.mokusakura.domain.Category;
import org.mokusakura.domain.Item;
import org.mokusakura.domain.Product;
import org.mokusakura.persistence.mapper.CategoryMapper;
import org.mokusakura.persistence.mapper.ItemMapper;
import org.mokusakura.persistence.mapper.ProductMapper;
import org.mokusakura.service.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CatalogServiceImpl implements CatalogService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    private ItemMapper itemMapper;

    //private ProductMapper productMapper;
    public CatalogServiceImpl() {
    }


    public List<Category> getCategoryList() {
        return categoryMapper.getCategoryList();
    }


    public Category getCategory(String categoryId) {
        return categoryMapper.getCategoryById(categoryId);
    }


    public Product getProduct(String productId) {
        return productMapper.getProduct(productId);
    }


    public List<Product> getProductListByCategory(String categoryId) {
        return productMapper.getProductListByCategoryId(categoryId);
    }


    public Boolean categoryIdExists(String categoryId) {
        return categoryMapper.getCategoryById(categoryId) != null;
    }


    public Boolean productIdExists(String productId) {
        return productMapper.getProduct(productId) != null;
    }


    public List<Item> getItemListByProduct(String productId) {
        return itemMapper.getItemListByProduct(productId);
    }


    public Item getItem(String itemId) {
        return itemMapper.getItem(itemId);
    }


    public List<Product> searchProductByKeyword(String keyword) {
        return productMapper.searchProductList("%" + keyword + "%");
    }


    public boolean isItemInStock(String itemId) {
        return itemMapper.getInventoryQuantity(itemId) > 0;
    }
}
